#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define NUMBER	500000

#define FORZ(i, max)	for(i = 0; i < max; i++)

typedef long long int ll;

int main() {
	int n,v,f=0;
	char s[2],c;
	ll t[26]; memset(t,0ll,sizeof(t));
	scanf("%d",&n);
	while(n--) {
		scanf("%s %d",s,&v);
//		printf("read=%s %d\n",s,v);
		t[s[0]-'A']+=v;
		f|=1<<(s[0]-'A');
	}
	FORZ(c,26) {
		if((f&1<<c)>0)
			printf("%c %lld\n",c+'A',t[c]);
	}
	return 0;
}
